package com.appwoo.txtws.activity;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.appwoo.txtws.adapter.BookstoreAdapter;
import com.appwoo.txtws.bean.BookBean;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.service.BookService;
import com.appwoo.txtws.wheel.widget.PageListView;
import com.appwoo.txtws.wheel.widget.PageListView.OnRefreshListener;
import java.util.ArrayList;

public class BookstoreResultActivity extends BookActivity
  implements AbsListView.OnScrollListener, View.OnClickListener
{
  private static final int REQUEST_CODE_BOOKSTORE_SEARCH = 1;
  private boolean blDataTask = false;
  private int bookType;
  private ArrayList<BookBean> books = new ArrayList();
  private DisplayMetrics dm;
  private int firstExtra;
  private Boolean isFoot = Boolean.valueOf(false);
  private String keyword;
  private int listItemHeight;
  private BookstoreAdapter mAdapter;
  private RelativeLayout mLayoutBookStoreResultHeader;
  private PageListView mLvSearchResultList;
  private TextView mTvBookstoreResultSearchKeyword;
  private int page = 1;
  private int pageSize = 10;
  private BookService service;
  private String strGrade;
  private String subject;

  private void findView()
  {
    Intent localIntent = getIntent();
    this.bookType = localIntent.getIntExtra("bookType", -1);
    this.strGrade = localIntent.getStringExtra("grade");
    this.subject = localIntent.getStringExtra("subject");
    if (this.bookType == -1)
      finish();
    if (this.strGrade == null)
      finish();
    ((InputMethodManager)getSystemService("input_method")).toggleSoftInput(0, 2);
    this.mTvBookstoreResultSearchKeyword = ((TextView)findViewById(2131492998));
    this.mLayoutBookStoreResultHeader = ((RelativeLayout)findViewById(2131492995));
    this.mLvSearchResultList = ((PageListView)findViewById(2131492985));
    this.service = new BookService(this);
    this.dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(this.dm);
  }

  private ArrayList<BookBean> getBookBykeyword()
  {
    String str = this.strGrade;
    if (this.strGrade != null)
    {
      if (this.strGrade.indexOf("18") <= -1)
        break label77;
      str = str + ",10,11,12";
    }
    while (true)
    {
      return this.service.getBookBeanList(Global.USERNAME, this.keyword, this.bookType, str, this.subject, this.page, this.pageSize);
      label77: if (this.strGrade.indexOf("19") > -1)
        str = str + ",13,14,15,16,17";
    }
  }

  private void getListItemHeight()
  {
    this.dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(this.dm);
    int i = this.mLayoutBookStoreResultHeader.getHeight();
    int j = SyncTutorialActivity.getStatusHeight(this);
    int k = this.dm.heightPixels - i - j;
    this.listItemHeight = (k / 5);
    this.firstExtra = (k % 5);
  }

  private void loadData()
  {
    this.books = new ArrayList();
    if (!isNetworkAvailable(this))
    {
      alertMessage(getString(2131428051));
      for (int i = 0; ; i++)
      {
        if (i >= 5)
        {
          if (this.mAdapter != null)
          {
            this.mAdapter.addData(this.books);
            this.mAdapter.notifyDataSetChanged();
          }
          closeProgress();
          this.blDataTask = true;
          this.mLvSearchResultList.onLoadMoreComplete();
          if (!this.mLvSearchResultList.getIsNoMore())
          {
            this.mLvSearchResultList.hideFotterMoreView();
            this.mLvSearchResultList.setIsNoMore(true);
          }
          return;
        }
        this.books.add(null);
      }
    }
    new SearchBookTask().execute(new String[0]);
  }

  private void search(String paramString)
  {
    if ((paramString == null) || ("".equals(paramString)))
      return;
    this.page = 1;
    this.mAdapter.clearListData();
    this.keyword = paramString;
    this.mTvBookstoreResultSearchKeyword.setText(paramString);
    loadData();
  }

  private void setView()
  {
    this.mTvBookstoreResultSearchKeyword.setOnClickListener(this);
    this.mLvSearchResultList.setOnScrollListener(this);
    this.mLayoutBookStoreResultHeader.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
      public void onGlobalLayout()
      {
        if (BookstoreResultActivity.this.mAdapter == null)
        {
          String str = BookstoreResultActivity.this.getIntent().getStringExtra("keyword");
          BookstoreResultActivity.this.getListItemHeight();
          BookstoreResultActivity.this.mAdapter = new BookstoreAdapter(BookstoreResultActivity.this, BookstoreResultActivity.this.books, BookstoreResultActivity.this.listItemHeight, BookstoreResultActivity.this.firstExtra);
          BookstoreResultActivity.this.mAdapter.setBookType(BookstoreResultActivity.this.bookType);
          BookstoreResultActivity.this.mAdapter.setGrade(BookstoreResultActivity.this.strGrade);
          BookstoreResultActivity.this.mAdapter.setSubject(BookstoreResultActivity.this.subject);
          BookstoreResultActivity.this.mLvSearchResultList.setAdapter(BookstoreResultActivity.this.mAdapter);
          BookstoreResultActivity.this.search(str);
        }
      }
    });
    this.mLvSearchResultList.setOnLoadMoreListener(new PageListView.OnRefreshListener()
    {
      public void onRefresh()
      {
        if ((!BookstoreResultActivity.this.mLvSearchResultList.getIsNoMore()) && (BookstoreResultActivity.this.blDataTask))
        {
          BookstoreResultActivity.this.mLvSearchResultList.prepareForRefreshMore();
          BookstoreResultActivity.this.isFoot = Boolean.valueOf(true);
          BookstoreResultActivity.this.loadData();
        }
      }
    });
  }

  protected void backKeyCallBack()
  {
    super.backKeyCallBack();
    finish();
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    if ((paramInt1 == 1) && (paramInt2 == -1))
      search(paramIntent.getStringExtra("keyword"));
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
      return;
    case 2131492998:
    }
    Intent localIntent = new Intent(this, BookstoreSearchActivity.class);
    localIntent.putExtra("before", "before");
    startActivityForResult(localIntent, 1);
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903065);
    findView();
    setView();
  }

  public void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3)
  {
  }

  public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt)
  {
    if ((paramInt == 0) && (paramAbsListView.getLastVisiblePosition() == -1 + paramAbsListView.getCount()) && (!this.mLvSearchResultList.getIsNoMore()) && (this.blDataTask))
    {
      this.mLvSearchResultList.prepareForRefreshMore();
      this.isFoot = Boolean.valueOf(true);
      loadData();
    }
  }

  class SearchBookTask extends AsyncTask<String, Integer, String>
  {
    SearchBookTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      BookstoreResultActivity.this.books = BookstoreResultActivity.this.getBookBykeyword();
      return null;
    }

    protected void onPostExecute(String paramString)
    {
      super.onPostExecute(paramString);
      if ((BookstoreResultActivity.this.books == null) || (BookstoreResultActivity.this.books.isEmpty()))
      {
        if (BookstoreResultActivity.this.mAdapter.getCount() == 0);
        for (int i = 0; ; i++)
        {
          if (i >= 5)
          {
            BookstoreResultActivity.this.mAdapter.addData(BookstoreResultActivity.this.books);
            BookstoreResultActivity.this.mAdapter.notifyDataSetChanged();
            BookstoreResultActivity.this.mLvSearchResultList.onLoadMoreComplete();
            BookstoreResultActivity.this.blDataTask = true;
            BookstoreResultActivity.this.mLvSearchResultList.hideFotterMoreView();
            BookstoreResultActivity.this.mLvSearchResultList.setIsNoMore(true);
            if (!BookstoreResultActivity.this.isFoot.booleanValue())
            {
              BookstoreResultActivity.this.closeProgress();
              BookstoreResultActivity.this.isFoot = Boolean.valueOf(false);
            }
            return;
          }
          BookstoreResultActivity.this.books.add(null);
        }
      }
      if (BookstoreResultActivity.this.books.size() < 5)
        if (BookstoreResultActivity.this.mAdapter.getCount() == 0)
        {
          if (BookstoreResultActivity.this.books.size() < 5)
            break label321;
          BookstoreResultActivity.this.mLvSearchResultList.hideFotterMoreView();
          BookstoreResultActivity.this.mLvSearchResultList.setIsNoMore(true);
        }
      while (true)
      {
        BookstoreResultActivity.this.blDataTask = true;
        BookstoreResultActivity.this.mAdapter.addData(BookstoreResultActivity.this.books);
        BookstoreResultActivity.this.mAdapter.notifyDataSetChanged();
        BookstoreResultActivity.this.mLvSearchResultList.onLoadMoreComplete();
        if (!BookstoreResultActivity.this.isFoot.booleanValue())
        {
          BookstoreResultActivity.this.closeProgress();
          BookstoreResultActivity.this.isFoot = Boolean.valueOf(false);
        }
        BookstoreResultActivity localBookstoreResultActivity = BookstoreResultActivity.this;
        localBookstoreResultActivity.page = (1 + localBookstoreResultActivity.page);
        return;
        label321: BookstoreResultActivity.this.books.add(null);
        break;
        if (BookstoreResultActivity.this.books.size() < 10)
        {
          BookstoreResultActivity.this.mLvSearchResultList.hideFotterMoreView();
          BookstoreResultActivity.this.mLvSearchResultList.setIsNoMore(true);
        }
        else
        {
          BookstoreResultActivity.this.mLvSearchResultList.showFooterMoreView();
          BookstoreResultActivity.this.mLvSearchResultList.setIsNoMore(false);
        }
      }
    }

    protected void onPreExecute()
    {
      super.onPreExecute();
      BookstoreResultActivity.this.blDataTask = false;
      if (!BookstoreResultActivity.this.isFoot.booleanValue())
        BookstoreResultActivity.this.showProgress("");
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.BookstoreResultActivity
 * JD-Core Version:    0.6.2
 */